#include <stdio.h>
#include <sys/mman.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>

int main() {
	char *p;
	int ret;
	p = (char*)mmap(0, 1024, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
	if (MAP_FAILED == p) {
		perror("mmap error");
		return 0;
	}

	pid_t pid = fork();
	if (pid == 0) {
		strcpy(p, "HelloWorld");
		printf("child *p = '%s'\n", p);
	} else if (pid > 0) {
		wait(0);
		printf("parent *p = '%s'\n", p);

		ret = munmap(p, 1024);
		if (-1 == ret) {
			perror("munmap error");
			return 0;
		}
	} else {
		perror("fork error");
	}

	return 0;
}
